using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;



namespace WinSSHMenu
{
    public partial class Submenu : Form
    {
        TreeNode parentNode = null;
        String _action;

        public String Action
        {
            get { return _action; }
            set { _action = value; }
        }


        public Submenu()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Add or edita submenu.  If folder node is currently 
        /// selected, this will edit the sub menu otherwise it will 
        /// add this as as a child of the currently selected node.  If
        /// no node is selected or a host is selected, a new root node is
        /// added.
        /// </summary>
        /// <param name="sender">Event Sender</param>
        /// <param name="e">Event args</param>
        private void button1_Click(object sender, EventArgs e)
        {
            TreeNode newNode = new TreeNode();
            newNode.Text = txtSubmenuName.Text;
            newNode.Tag = Constants.TYPE_SUBMENU;

            // Make the icon for this item a folder
            newNode.ImageIndex = 0;

            parentNode.TreeView.BeginUpdate();
            if (Action.Equals(Constants.ACTION_EDIT))
            {
                parentNode.TreeView.SelectedNode.Text = txtSubmenuName.Text;
            }
            else
            {
                parentNode.Nodes.Add(newNode);
            }
            parentNode.TreeView.EndUpdate();
            parentNode.TreeView.SelectedNode = newNode;

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public System.Windows.Forms.TreeNode ParentNode
        {
            get { return this.parentNode; }
            set { this.parentNode = value; }
        }
    }
}